package ${packagePrefix}.domain.model.${domainObjectName?uncap_first};

import ${packagePrefix}.domain.model.${domainObjectName?uncap_first}.${domainObjectName}Entity;
import ${packagePrefix}.domain.gateway.${domainObjectName}Gateway;
import ${packagePrefix}.infrastructure.dataobject.${domainObjectName}DO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ${tableComment!""} 工厂类
 */
@Component
public class ${domainObjectName}Factory {

    /**
     * 将数据对象转换为领域实体
     *
     * @param dataObject 数据对象
     * @return 领域实体
     */
    public ${domainObjectName}Entity toEntity(${domainObjectName}DO dataObject) {
        if (dataObject == null) {
            return null;
        }
        
        return ${domainObjectName}Entity.builder()
                .id(dataObject.getId())
<#list fields as field>
    <#if field.name != "id" && field.name != "gmtCreate" && field.name != "gmtModified">
                .${field.name}(dataObject.get${field.name?cap_first}())
    </#if>
</#list>
<#if hasDateFields>
                .gmtCreate(dataObject.getGmtCreate())
                .gmtModified(dataObject.getGmtModified())
</#if>
                .build();
    }

    /**
     * 将领域实体转换为数据对象
     *
     * @param entity 领域实体
     * @return 数据对象
     */
    public ${domainObjectName}DO toDO(${domainObjectName}Entity entity) {
        if (entity == null) {
            return null;
        }
        
        ${domainObjectName}DO dataObject = new ${domainObjectName}DO();
        dataObject.setId(entity.getId());
<#list fields as field>
    <#if field.name != "id" && field.name != "gmtCreate" && field.name != "gmtModified">
        dataObject.set${field.name?cap_first}(entity.get${field.name?cap_first}());
    </#if>
</#list>
        return dataObject;
    }

    /**
     * 将数据对象列表转换为领域实体列表
     *
     * @param dataObjectList 数据对象列表
     * @return 领域实体列表
     */
    public List<${domainObjectName}Entity> toEntityList(List<${domainObjectName}DO> dataObjectList) {
        if (dataObjectList == null || dataObjectList.isEmpty()) {
            return new ArrayList<>();
        }
        
        return dataObjectList.stream()
                .map(this::toEntity)
                .collect(Collectors.toList());
    }
} 